/*
 * Boss.cpp
 *
 *  Created on: 06/12/2011
 *      Author: arleudo
 */

#include "objetos/Boss.h"

namespace objetos
{
	//--------------------------------------------------------------------------------
	Boss::Boss( sf::Sprite* target )
			: Enemy( target )
	{

	}
	//--------------------------------------------------------------------------------
	Boss::~Boss( void )
	{

	}
	//--------------------------------------------------------------------------------
	void Boss::load( void )
	{
		std::string sourcePath = "resources/gambit/";
		std::string sourceExtension = ".png";

		std::string str = "Walk";
		Asset::getInstance()->loadImages( sourcePath, str, sourceExtension, 4, vecRight );

		str = "Frame";
		Asset::getInstance()->loadImages( sourcePath, str, sourceExtension, 6, vecAttacking );

		setX( 600 );
		setY( 400 );

		Animation* A_RunnerRight = new Animation( vecRight, 0.2 );
		Animation* A_Attacking = new Animation( vecAttacking, 0.05 );

		addAnimation( A_RunnerRight );
		addAnimation( A_Attacking );

	}
	//--------------------------------------------------------------------------------
	void Boss::move( void )
	{
		bool apertou = false;

		if ( IS_KEY_DOWN(Right) )
		{
			apertou = true;
			//vel.x += ACCEL;
			if ( vel.x > MAX_VELOCITY )
			{
				vel.x = MAX_VELOCITY;
			}
		}

		if ( IS_KEY_DOWN(Left) )
		{
			apertou = true;
			//vel.x -= ACCEL;
			if ( vel.x < MAX_MINIM )
			{
				vel.x = MAX_MINIM;
			}
		}
		if ( IS_KEY_DOWN(Space) && !isJumping() )
		{
			vel.y = -getJumpForce();
			setJumping( true );
		}

		if ( !apertou || ( IS_KEY_DOWN(Right) && IS_KEY_DOWN(Left) ) )
		{
			vel.x = 0;
		}
	}
	//--------------------------------------------------------------------------------
	void Boss::runAnimation( void )
	{
		if ( IS_KEY_DOWN(Right) )
			this->setImage( getAnimation().at( 0 )->run() );
		else
			this->setImage( getAnimation().at( 1 )->run() );
	}
//--------------------------------------------------------------------------------
	void Boss::update( void )
	{
		if ( getSprite()->GetPosition().x > 1000 )
		{
			getSprite()->SetPosition( getSprite()->GetPosition().x, 400 );
		}

		getSprite()->Move( vel );

		runAnimation();
		move();
	}

} // namespace objetos

